<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../styles/register.css" />
<title>修改密码</title>
<script type="text/javascript">
	function checkPass() {
		var pwd1 = document.getElementById("password1").value;
		var pwd2 = document.getElementById("password2").value;
		if (pwd1 != pwd2) {
			document.getElementById("errorpwd").style.display = "block";
			return false;
		}
	};
</script>
</head>
<body>
<?php
if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '确认修改') {
	// 获取浏览器发过来的页面数据
	$u = $_POST ['user_original_pad'];
	$p = $_POST ['user_password'];
	// 加载数据库连接
	include '../includes/dbhelper.php';
//	$conn = mysql_connect ( "localhost", "root", "111111" ) or die ( "数据库连接错误" );
//	mysql_select_db ( "bookmgr", $conn ) or die ( "数据库访问错误" );
//	mysql_query ( "set names utf8" );
	session_start ();
	// if (isset ( $_SESSION ["userinfo"] ) and ! empty ( $_SESSION ["userinfo"] ["account"] )) {
	// echo "欢迎" . $_SESSION["userinfo"] ["account"] . ",<a href='login.php' name='logout' target='_self'>退出</a>";
	// } else {
	// header ( "location:login.php" );
	// }
	$user_account = $_SESSION ["userinfo"] ["account"];
	$result = mysql_query ( "select password from `bookmgr_user_info` where `account` ='$user_account'" );
	$row = mysql_fetch_assoc ( $result );
	if ($row ['password'] == md5 ( $u )) {
		$result2 = mysql_query ( "UPDATE `bookmgr_user_info` SET `password`=md5('$p') WHERE `account`='$user_account'" );
		if (! ! $result2) {
			echo "<script>alert('修改密码成功')</script>";
		} else {
			echo "<script>alert('修改密码失败')</script>";
		}
	} else {
		echo "<script>alert('原始密码错误')</script>";
	}
	mysql_close ( $conn );
}
?>
	<form action="./alterPassword.php" target="frm" method="post">
		<div>
			<h1>修改密码</h1>
			<h2>用户信息</h2>
			<div class="table_style">
				<label> 原密码： </label> <input type="password"
					name="user_original_pad"> </input>
			</div>
			<div class="table_style">
				<label> 新密码： </label> <input type="password" id="password1"
					name="user_password"> </input>
			</div>
			<div class="table_style">
				<label> 重新输入： </label> <input type="password" id="password2"
					onblur="return checkPass();"> </input><span id="errorpwd"
					style="display: none;">两次输入密码不一致</span>
			</div>
			<!--  
			<h2>使用密保问题修改密码</h2>
			<div class="table_style">
				<label> 是否开启： </label> <input class="redio_style" type="radio"
					name="is_secure" checked="checked" value="yes"> </input>是<input
					class="redio_style" type="radio" name="is_secure" value="no"> </input>否
			</div>
			<div class="table_style">
				<label> 安全问题： </label> <select class="select_style"
					name="user_question" id="select">
					<option value="1" selected="selected">请选择···</option>
					<option value="2">你最喜欢的人</option>
					<option value="3">你最好的朋友</option>
				</select> </input>
			</div>
			<div class="table_style">
				<label> 回答问题： </label> <input type="text" name="user_answer"> </input>
			</div>
			-->
			<div class="button_style">
				<input class="button" name="user_submit" type="submit" value="确认修改" />
				<input class="button" type="reset" value="重新填写" />
			</div>
		</div>
	</form>
</body>
</html>
